﻿#region summary

// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

#endregion

using System.Diagnostics;

namespace NSQL.Expressions
{
    [DebuggerDisplay("Value:{Value}")]
    public abstract class ValueExpression : BaseExpression, IValueExpression
    {
        public object Value { get; set; }

        protected ValueExpression(object value) => Value = value;

        #region [operator override]

        public static ValueExpression operator +(ValueExpression v1, ValueExpression v2)
        {
            var o1 = v1.Value;
            var o2 = v2.Value;
            var dyn = (dynamic) o1 + (dynamic) o2;
            return (ValueExpression) dyn;
        }

        public static ValueExpression operator -(ValueExpression v1, ValueExpression v2)
        {
            var o1 = v1.Value;
            var o2 = v2.Value;
            var dyn = (dynamic) o1 - (dynamic) o2;
            return (ValueExpression) dyn;
        }

        public static ValueExpression operator -(ValueExpression v1)
        {
            var o1 = v1.Value;
            var dyn = -(dynamic) o1;
            return (ValueExpression) dyn;
        }

        public static ValueExpression operator *(ValueExpression v1, ValueExpression v2)
        {
            var o1 = v1.Value;
            var o2 = v2.Value;
            var dyn = (dynamic) o1 * (dynamic) o2;
            return (ValueExpression) dyn;
        }

        public static ValueExpression operator /(ValueExpression v1, ValueExpression v2)
        {
            var o1 = v1.Value;
            var o2 = v2.Value;
            var dyn = (dynamic) o1 / (dynamic) o2;
            return (ValueExpression) dyn;
        }

        public static ValueExpression operator %(ValueExpression v1, ValueExpression v2)
        {
            var o1 = v1.Value;
            var o2 = v2.Value;
            var dyn = (dynamic) o1 % (dynamic) o2;
            return (ValueExpression) dyn;
        }

        #endregion
    }
}